<template>
    <div id="line2" :style="{height:height,width:width}"/>
</template>

<script>


export default {
    props: {
        className: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '100%'
        },
        height: {
            type: String,
            default: '260px'
        },
        xAxisData: {
            type: Array,
            default:()=>['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        data:{
            type:Array,
            default:()=>[820, 932, 901, 934, 1290, 1330, 1320]
        }
    },
    data() {
        return {
            myChart: null
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.initChart()
        })
    },
    methods: {
        initChart() {
            let chartDom = document.getElementById('line2')
            this.myChart = this.$echarts.init(chartDom)

            let option
            option = {
                xAxis: {
                    type: 'category',
                    data: this.xAxisData
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: this.data,
                        type: 'line',
                        smooth: true
                    }
                ]
            }
            this.myChart.setOption(option)
            // 监听window窗口大小变化的事件
            window.addEventListener('resize', () => {
                this.myChart.resize()
            })
        }
    }
}
</script>
